Skip to content

[deprecation] Deprecate AddInterfaceByTraitRector - #8346

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-add-interface-by-trait-rector
Aug 10, 2026
Merged

[deprecation] Deprecate AddInterfaceByTraitRector#8346
TomasVotruba merged 1 commit into
mainfrom
deprecate-add-interface-by-trait-rector

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Pairing a trait with an interface is specific to a single project or package. In practice the mapping needs extra conditions - only for classes in a certain namespace, only when the trait is used directly, only when a matching method exists - none of which a plain trait => interface map can express. A custom rule is a better fit.

The rule is not part of any set - neither in rector-src config/set/, nor in rector-symfony, rector-doctrine, rector-phpunit, rector-laravel or drupal-rector.

What the rule did:

$rectorConfig->ruleWithConfiguration(AddInterfaceByTraitRector::class, [
    'SomeTrait' => 'SomeInterface',
]);
-class SomeClass
+class SomeClass implements SomeInterface
 {
     use SomeTrait;
 }

The class carried an @api used in rector-doctrine note, but rector-doctrine has no reference to it anymore, so the tag was stale and is dropped.

Follows the same shape as the recently deprecated rules - DeprecatedInterface, refactor() throws, tests removed.

@TomasVotruba
TomasVotruba force-pushed the deprecate-add-interface-by-trait-rector branch from ec5511b to 4144291 Compare August 10, 2026 22:13
@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 10, 2026 22:14
@TomasVotruba
TomasVotruba merged commit 768539a into main Aug 10, 2026
52 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-add-interface-by-trait-rector branch August 10, 2026 22:14
@bobvandevijver

Copy link
Copy Markdown

@TomasVotruba Very sorry to see this rule go. It was extremely convenient to have...

Pairing a trait with an interface is specific to a single project or package.

Yes, but

In practice the mapping needs extra conditions

No. Never needed any extra condition for this one....

Also, it now throws an error making rector return a failure (1), so there is also something wrong with the deprecation process.

 [ERROR] Could not process                                                      
         "/builds/8bAKuozDA/0/idb/idb/src/Idb/AdminGeneratorBundle/Form/Type/Adm
         inLottery/Options.php" file, due to:                                   
         "System error:                                                         
         ""Rector\Transform\Rector\Class_\AddInterfaceByTraitRector" rule is    
         deprecated, as too niche; use a custom rule scoped to your own trait   
         and interface pair instead"                                            
         Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On line:
         47
 [WARNING] Registered rule "Rector\Transform\Rector\Class_\AddInterfaceByTraitRector" is deprecated and will be removed.
           Upgrade your config to use another rule or remove it

@TomasVotruba

Copy link
Copy Markdown
Member Author

Use custom rule instead, if you need this one.

@rectorphp rectorphp locked as resolved and limited conversation to collaborators Aug 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants